import provinceData from './city-data/province.js'
import cityData from './city-data/city.js'
import areaData from './city-data/area.js'

export function getCityPickerValue (p = '', c = '', a = '') {
	let result = [0, 0, 0]
	// 获取省级index
	let p_index = provinceData.findIndex(el => (el.label == p))
	if (p_index === -1 || !cityData[p_index]) return result
	result[0] = p_index
	// 获取市级index
	let c_index = cityData[p_index].findIndex(el => (el.label == c))
	if (c_index === -1 || !areaData[p_index][c_index]) return result
	result[1] = c_index
	// 获取区级index
	let a_index = areaData[p_index][c_index].findIndex(el => (el.label == a))
	if (a_index === -1) return result
	result[2] = a_index
	
	return result
}

export function getCityCode (p = '', c = '', a = '') {
	let result = [0, 0, 0]
	let value = ''
	// 获取省级index
	let p_index = provinceData.findIndex(el => (el.label == p))
	if (p_index === -1) return ''
	value = provinceData[p_index].value
	if (!cityData[p_index]) return value
	result[0] = p_index
	// 获取市级index
	let c_index = cityData[p_index].findIndex(el => (el.label == c))
	if (c_index !== -1) value = cityData[p_index][c_index].value
	if (!areaData[p_index][c_index]) return value
	result[1] = c_index
	// 获取区级index
	let a_index = areaData[p_index][c_index].findIndex(el => (el.label == a))
	console.log(a_index)
	if (a_index !== -1) value = areaData[p_index][c_index][a_index].value
	
	return value
}